In software development, source code is often written in a high-level language easily understood by humans, and is converted into machine-readable object code by a compiler. When writing source code, a set of operations is defined as a function in order to increase the reusability. Thus, the function is used repeatedly by executing a function call.
However, if a processor simply executes a function call, overhead is incurred to save and replace the content such as the values of registers. That is, frequent execution of function calls might reduce the performance. Thus, some compilers perform inline expansion of function calls as a way of compiler optimization. Inline expansion of function calls is an optimization technique that replaces a function call instruction with instructions included in the called function, and thereby reduces the number of function calls in the object code. Inline expansion of function calls often improves the performance of object code.
However, in many cases, when function calls are inlined, the number of instructions in the calling program module increases. If the number of instructions increases, the instruction cache of the processor might not be able to store all the instructions of the program module. This might cause frequent replacement of instructions in the instruction cache, and result in a reduction in performance. Thus, there has been proposed an optimization method to be performed by a compiler. This optimization method estimates the object code size in the case where a function call is inlined, and inlines the function call only when the estimated object code size does not exceed the size of the instruction cache.
There has also been proposed a compiler that determines for each function call whether to perform inline expansion. The proposed compiler estimates, for a function call, the number of times the loop to which the function call belongs is executed. The compiler calculates a determination value of the function call, based on the estimated loop count, the object code size of the called function, and the properties of the target processor. When the calculated determination value is greater than a predetermined threshold, the compiler determines to inline the function call.
There has also been proposed a program conversion apparatus that selects a function to be subjected to optimization from a plurality of functions. The proposed program conversion apparatus counts, for each of a plurality of functions, instructions in the function that access variables. The program conversion apparatus selects a function with the highest count of instructions, and inlines a function call that calls the selected function.
See, for example, Japanese Laid-open Patent Publications No. 5-120029, No. 6-202875 and No. 2001-282546.
Among a plurality of function calls, there exist function calls whose inline expansion greatly improves the performance, and function calls whose inline expansion does not greatly improve the performance. Therefore, it is preferable to select and inline a function call whose inline expansion improves the performance as much as possible, under the constraints of the size of the instruction cache and the like. However, the proposed compiler described above is configured to determine for each function call whether to perform inline expansion, and is not configured to select a function call to be inlined, from a plurality of function calls. Further, the proposed program conversion apparatus described above is configured to inline a function call that calls a function with the greatest number of instructions involving access to a variable. That is, there is still room for improvement in terms of performance.